<%--     Document   : booktrip
    Created on : May 5, 2008, 9:40:46 PM
    Author     : Administrator
--%>

<%@ page import="java.util.Date" %>
<%@ page import="java.lang.String" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="Model.Trip" %>
<%@ page import="java.util.List" %>
<%@ page import="AirLine.Flight" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Book Trip here</h2>
        <%
            String test = request.getParameter("id");
            int num = Integer.valueOf(test);
            //System.out.println(test);
            Integer total = (Integer) session.getAttribute("number");
            int number = total.intValue();
            //out.print("<br> number of passengers: " + number );
            Set trips = (Set) session.getAttribute("trips");

            Iterator<Trip> it = trips.iterator();


            for (int count = 0; it.hasNext(); count++) {
                // jump to next
                if (count == num) {
                    Trip temp = it.next();
                    session.setAttribute("trip", temp);
                    out.print("<h3>" + temp.getDepartureAirport() + " -->>" + temp.getDestinationAirport() + " price: " + temp.getPrice() + "<br></h3>");

                    List<Flight> flights = temp.getFlights();
                    Iterator<Flight> it2 = flights.iterator();
                    out.print("detail: ");
        %>
        
        
        <table border="3">
            <thead>
                <tr>
                    <th>Airline</th>
                    <th>Departure Airport</th>
                    <th>Destination Airport</th>
                    <th>Departure Time</th>
                    <th>Destination Time</th>
                    <th>Free Seats</th>
                    <th>Price</th>
                </tr>
            </thead>
            <tbody>
                <%
                    while (it2.hasNext()) {
                        Flight tempFlight = it2.next();
                        String airline = tempFlight.getAirline().getName();
                        String departureAirport = tempFlight.getDepartureAirport().getAirportName();
                        String arrivalAirport = tempFlight.getDestinationAirport().getAirportName();

                        Date d1 = tempFlight.getDepartureTime();
                        String departureTime = d1.toString();
                        Date d2 = tempFlight.getArrivalTime();
                        String arrivalTime = d2.toString();

                        String freeSeats = "" + tempFlight.getNumberOfFreeSeats();
                        String price = "" + tempFlight.getPrice();
                %>
                <tr>
                    <td><%=airline%></td>
                    <td><%=departureAirport%></td>
                    <td><%=arrivalAirport%></td>
                    <td><%=departureTime%></td>
                    <td><%=arrivalTime%></td>
                    <td><%=freeSeats%></td>
                    <td><%=price%></td>
                </tr>
                
                <%
                    }
                %>
            </tbody>
        </table>
        <%
                } else {
                    it.next();
                }

            }
        %>
        
        
        <br><br>
        <h2>Passenger infomation<br>
        <form method="POST" action="BookTrip.do">
            
            <%
            for (int i = 0; i < number; i++) {
            %>
            <br><br>Passenger name:<input type="text" name="name<%=i%>">
            Person number:<input type="text" name="number<%=i%>">
            <select name="prefer<%=i%>" size="1">
                <option value="0">aisle
                <option value="1">window
            </select>
            <%
            }
            %>
            
            <input type="SUBMIT" value="BOOKs">
        </form>
    </body>
</html>
